package com.todo.biz.application.api.controller;

import com.todo.biz.application.convert.BizBaseConvert;
import com.todo.biz.application.entity.bo.BizImgExamineBO;
import com.todo.biz.application.entity.bo.BizTextExamineBO;
import com.todo.biz.application.entity.bo.ContentExamineData;
import com.todo.biz.application.service.BizExamineRecordService;
import com.todo.biz.service.api.BizExamineApi;
import com.todo.biz.service.api.request.CommentDetectionRequest;
import com.todo.biz.service.api.request.ContentDetectionRequest;
import com.todo.biz.service.api.request.ImgDetectionRequest;
import com.todo.biz.service.api.response.BaseExamineResponse;
import com.todo.common.common.entity.response.BizResponse;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.tags.Tag;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;

/**
 * @author azhebuxing
 * @date 2025/2/28 02:42
 * @description
 */
@RestController
@RequestMapping("/api/biz/examine")
@Tag(name = "服务端-计数器处理类", description = "服务端-计数器处理类")
public class BizExamineApiController implements BizExamineApi {

    @Resource
    private BizExamineRecordService bizExamineRecordService;

    @Override
    @Operation(summary = "文本内容检测")
    @PostMapping("/contentDetection")
    public BizResponse<BaseExamineResponse> contentDetection(@RequestBody ContentDetectionRequest request) {
        if (request == null || request.getContent() == null || request.getBizId() == null) {
            return BizResponse.paramError();
        }
        BizTextExamineBO bizTextExamineBO = new BizTextExamineBO();
        bizTextExamineBO.setContent(request.getContent());
        bizTextExamineBO.setSceneEnum(request.getSceneEnum());
        bizTextExamineBO.setBizId(request.getBizId());
        ContentExamineData contentExamineData = bizExamineRecordService.contentDetection(bizTextExamineBO);
        return BizResponse.success(BizBaseConvert.convertToBaseExamineResponse(contentExamineData));
    }

    @Override
    @Operation(summary = "评论内容检测")
    @PostMapping("/commentDetection")
    public BizResponse<BaseExamineResponse> commentDetection(@RequestBody CommentDetectionRequest request) {
        if (request == null || request.getContent() == null || request.getBizId() == null) {
            return BizResponse.paramError();
        }
        BizTextExamineBO bizTextExamineBO = new BizTextExamineBO();
        bizTextExamineBO.setContent(request.getContent());
        bizTextExamineBO.setSceneEnum(request.getSceneEnum());
        bizTextExamineBO.setBizId(request.getBizId());
        ContentExamineData contentExamineData = bizExamineRecordService.contentDetection(bizTextExamineBO);
        return BizResponse.success(BizBaseConvert.convertToBaseExamineResponse(contentExamineData));
    }

    @Override
    @Operation(summary = "图片内容检测")
    @PostMapping("/imgDetection")
    public BizResponse<BaseExamineResponse> imgDetection(@RequestBody ImgDetectionRequest request) {
        if (request == null || request.getImgUrl() == null || request.getBizId() == null) {
            return BizResponse.paramError();
        }
        BizImgExamineBO bizImgExamineBO = new BizImgExamineBO();
        bizImgExamineBO.setImgUrl(request.getImgUrl());
        bizImgExamineBO.setSceneEnum(request.getSceneEnum());
        bizImgExamineBO.setBizId(request.getBizId());
        ContentExamineData contentExamineData = bizExamineRecordService.imgDetection(bizImgExamineBO);
        return BizResponse.success(BizBaseConvert.convertToBaseExamineResponse(contentExamineData));
    }
}
